/*
 * @Description: 最小订单金额规则详情DS
 * @Version: 1.0
 * @Autor: c-jack.qian
 * @Date: 2021-02-24 11:56:54
 * @LastEditors: c-jack.qian
 * @LastEditTime: 2021-04-25 14:53:56
 */
import { DataSetSelection, FieldType } from 'choerodon-ui/pro/lib/data-set/enum';
import commonConfigStore from '@common/config/commonConfig';

import intl from 'utils/intl';

const O2_OM = process.env.NODE_ENV === 'development' ? '/o2om-c-xx' : commonConfigStore.O2_OM;
const orderDistributionDtlFormDS = () => ({
  autoQuery: false,
  selection: 'multiple',
  primaryKey: 'id',
  autoCreate: true,
  paging: false,
  transport: {
    read: config => {
      return {
        ...config,
        url: `${O2_OM}/v1/djiom-order-amount-rules/detail`,
        method: 'get',
      };
    },
    create: config => {
      const { data } = config;
      return {
        ...config,
        data: data[0],
        url: `${O2_OM}/v1/djiom-order-amount-rules/upsert`,
        method: 'post',
      };
    },
    update: config => {
      const { data } = config;
      return {
        ...config,
        data: data[0],
        url: `${O2_OM}/v1/djiom-order-amount-rules/upsert`,
        method: 'post',
      };
    },
  },
  fields: [
    {
      name: 'businessGroup',
      type: FieldType.string,
      label: intl.get('dji.otc.om.view.field.groupName').d('组别'),
      lookupCode: 'DJICM_GROUP',
      required: true,
    },
    {
      name: 'amountRuleType',
      type: FieldType.string,
      label: intl.get('dji.otc.om.view.field.amountRuleType').d('规则类型'),
      required: true,
      lookupCode: 'DJIOM.AMOUNT_RULE_TYPE',
    },
    {
      name: 'priority',
      type: FieldType.number,
      label: intl.get('dji.otc.om.view.field.orderPriority').d('优先级'),
      required: true,
    },
    // {
    //     name: 'largeAreaObj',
    //     type: FieldType.object,
    //     label: intl.get('dji.otc.om.view.field.tagName').d('大区'),
    //     required: true,
    //     labelWidth: 120,
    //     checkValueOnOptionsChange: true,
    //     lookupUrl: `${O2_CM}/v1/cm-contract-permissions/get-largeArea-info`,
    //     ignore: 'always',
    // },
    // {
    //     name: 'regionId',
    //     bind: 'largeAreaObj.value',
    //     type: FieldType.string,
    // },
    {
      name: 'regionId',
      type: FieldType.number,
      label: intl.get('dji.otc.om.view.field.region').d('大区'),
      required: true,
      lookupCode: 'DJICM_CHOOSE_BIG_AREA',
    },
    {
      name: 'areaControyLabel',
      type: FieldType.string,
      label: intl.get('dji.otc.om.view.field.areaControyLabel').d('区域国家'),
    },
  ],
});

const orderDistributionDtlTableDS = () => ({
  autoCreate: false,
  paging: false,
  transport: {
    read: config => {
      return {
        ...config,
        url: `${O2_OM}/v1/djiom-order-amount-rule-details`,
        method: 'get',
      };
    },
  },
  fields: [
    {
      name: 'minOrderValue',
      type: FieldType.number,
      label: intl.get('dji.otc.om.view.field.minOrderValue').d('订单最小金额'),
      required: true,
    },
    {
      name: 'valueCaculationRule',
      type: FieldType.number,
      label: intl.get('dji.otc.om.view.field.valueCaculationRule').d('订单金额计算规则'),
      required: true,
      lookupCode: 'DJIOM.VALUE_CACULATION_RULE',
    },
    {
      name: 'minOrderQuantity',
      type: FieldType.number,
      label: intl.get('dji.otc.om.view.field.minOrderQuantity').d('订单数量(min)'),
      required: true,
    },
    {
      name: 'maxOrderQuantity',
      type: FieldType.number,
      label: intl.get('dji.otc.om.view.field.maxOrderQuantity').d('订单数量(max)'),
      required: true,
    },
    {
      name: 'orderCycle',
      type: FieldType.string,
      label: intl.get('dji.otc.om.view.field.orderCycle').d('订单计算周期'),
      required: true,
      lookupCode: 'DJIOM.ORDER_CYCLE',
    },
    {
      name: 'quantityCaculationRule',
      type: FieldType.string,
      label: intl.get('dji.otc.om.view.field.quantityCaculationRule').d('订单数量计算规则'),
      required: true,
      lookupCode: 'DJIOM.QUANTITY_CACULATION_RULE',
    },
    {
      name: 'customerCode',
      type: FieldType.string,
      label: intl.get('dji.otc.om.view.field.customerTradeCode').d('交易身份客户'),
      // options: option,
      // required: true,
    },
    
  ],
});
// const option = new DataSet({
//   // paging: true,
//   pageSize:100,
//   selection: 'single' as DataSetSelection,
//   autoQuery: true,
//   transport: {
//     read: config => {
//       console.log(config,'config');
      
//       return {
//         ...config,
//         url: `${O2_OM}/v1/customer-interface/get-customer-trade-data`,
//         data: [],
//         method: 'get',
//         transformResponse: res => {
//           return JSON.parse(res).content;
//         },
//       };
//     },
//   },
// });

// 区域DS
const areaDateSet = () => ({
  primaryKey: 'value',
  selection: 'single' as DataSetSelection,
  autoQuery: false,
  paging: false,
  parentField: 'parentCodeValue',
  idField: 'value',
  expandField: 'expand',
  checkField: 'check',
  transport: {
    read: config => {
      return {
        ...config,
        url: `${O2_OM}/v1/pi-interface/get-area-tree-data`,
        method: 'get',
      };
    },
  },
});

// 请求订单的已选区域详情DS
const reqSelectedAreaDateSet = () => ({
  primaryKey: 'value',
  selection: 'single' as DataSetSelection,
  autoQuery: false,
  paging: false,
  parentField: 'parentCodeValue',
  idField: 'value',
  expandField: 'expand',
  checkField: 'check',
  transport: {
    read: config => {
      return {
        ...config,
        url: `${O2_OM}/v1/djiom-order-amount-rule-areas/region-list`,
        method: 'get',
      };
    },
  },
});

const reqCustomerDateSet = () => ({
  selection: 'single' as DataSetSelection,
  autoQuery: false,
  // paging: false,
  transport: {
    read: () => {
      return {
        url: `${O2_OM}/v1/customer-interface/get-customer-trade-data`,
        method: 'get',
      };
    },
  },
});

export {
  orderDistributionDtlFormDS,
  orderDistributionDtlTableDS,
  areaDateSet,
  reqSelectedAreaDateSet,
  reqCustomerDateSet
};
